package easyzhou.com.ui;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;

import javax.swing.JFileChooser;
import javax.swing.JFrame;

public abstract class DefaultJFileChooser extends JFileChooser {
		// fileChooser = new JFileChooser();
		private final JFrame parent;
		public DefaultJFileChooser(JFrame parent) {
			this.parent = parent;
		}

		public void init() {
			setFileSelectionMode(DIRECTORIES_ONLY);
			int returnValue = showOpenDialog(parent);
			addActionListener(new ActionListener() {

				@Override
				public void actionPerformed(ActionEvent e) {
					int returnValue = showOpenDialog(parent);
					System.out.println("returnValue " + returnValue);
					if (returnValue == JFileChooser.APPROVE_OPTION) {
						doSelectionFile(getSelectedFile());
						doSelectedFiles(getSelectedFiles());
					}
				}

			});
		}

		protected void doSelectedFiles(File[] selectedFiles) {
		}

		protected abstract void doSelectionFile(File selectedFile);

	}